package com.school.information.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.school.information.entity.SysRoleMenuEntity;
import com.school.information.mapper.SysRoleMenuMapper;
import com.school.information.service.SysRoleMenuService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (SysRoleMenu)表服务实现类
 *
 * @author ycc
 * @since 2023-05-28 23:25:50
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenuEntity> implements SysRoleMenuService {
//    @Override
//    public List<SysRoleMenuEntity> findByRoleIds(List<Long> roleIds) {
//        return baseMapper.selectList(Wrappers.<SysRoleMenuEntity>query().lambda().in(SysRoleMenuEntity::getRoleId, roleIds));
//    }
//
//    @Override
//    public Set<String> findPermsByRoleIds(List<Long> roleIds) {
//        List<SysRoleMenuEntity> list = findByRoleIds(roleIds);
//        return null;
//    }


    @Override
    public void delByRoleId(Long roleId) {
        this.remove(Wrappers.<SysRoleMenuEntity>lambdaQuery().eq(SysRoleMenuEntity::getRoleId, roleId));
    }

    @Override
    public void delByRoleIds(List<Long> roleIds) {
        this.remove(Wrappers.<SysRoleMenuEntity>lambdaQuery().in(SysRoleMenuEntity::getRoleId, roleIds));
    }

    @Override
    public List<Long> findByRoleId(Long roleId) {
        List<SysRoleMenuEntity> roleMenuList = this.list(Wrappers.<SysRoleMenuEntity>query().lambda().eq(SysRoleMenuEntity::getRoleId, roleId));
        List<Long> menuIds = roleMenuList.stream().map(SysRoleMenuEntity::getMenuId).collect(Collectors.toList());
        return menuIds;
    }
}
